<template>
  <div>
    <div v-for="(item,i) in detailsDatas" :key="i">
      <el-row type="flex">
        <el-col :span="1">
          {{ i+1 }}
        </el-col>
        <el-col :span="21" class="product">
          <el-button class="bg" type="text">{{ item.type.slice(0,2) }}</el-button>
          <p style="margin:0px 10px;">{{ item.type==='物品类'?item.materialMedicineDto.name:item.productDto.name }}</p>
        </el-col>
        <el-col :span="2">
          X {{ item.count }}
        </el-col>
      </el-row>
      <el-row v-if="item.type==='项目类'||item.type==='物品类'" class="grey">
        <el-col :span="20" :offset="1">
          <span>规格：{{ item.type==='物品类'?item.materialMedicineDto.spec:item.productDto.spec }}</span>
          <span>单位：{{ item.type==='物品类'?item.materialMedicineDto.unit:item.productDto.unit }}</span>
          <span v-if="item.type==='项目类'">使用次数：{{ item.productDto.usageTimes }}</span>
        </el-col>
      </el-row>
      <el-row type="flex" class="price">
        <el-col :span="6" :offset="1">
          售价：￥{{ item.comboPrice==='0'?item.comboPrice:Number(item.comboPrice)/Number(item.discount)*100 }}
        </el-col>
        <el-col :span="5">
          套餐折扣：<span class="span">{{ item.discount }}%</span>
        </el-col>
        <el-col v-if="item.discount" :span="8">
          套餐金额：<span class="span">￥{{ item.comboPrice }}</span>
        </el-col>
      </el-row>
    </div>
    <el-row>
      <el-col :offset="18" :span="7">原价：￥{{ detailsDatas | detailPrice(1) }}</el-col>
      <el-col :offset="18" :span="7">折扣：-￥{{ detailsDatas | detailPrice(2) }}</el-col>
      <el-col :offset="17" :span="7">套餐价格：<span class="span">￥{{ detailsDatas | detailPrice(3) }}</span></el-col>
    </el-row>
  </div>
</template>

<script>
import { detailPrice } from '@/api/fifters.js';
export default {
  filters: {
    detailPrice(arr, number) {
      return detailPrice(arr, number);
    },
  },
  props: {
    detailsId: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      detailsDatas: [],
    };
  },
  watch: {
    detailsId: {
      handler(newId) {
        this.fetchData(newId);
      },
      deep: true,
    },
  },
  mounted() {
    this.fetchData(this.detailsId);
  },
  methods: {
    async fetchData(id) {
      const res = await this.$api['doctor/consulting/comboDetail']({ 'id': id });
      if (res.code !== 200) return this.$message.error('查询套餐详情失败！');
      console.log(res);
      this.detailsDatas = res.data.comboDetailDtoList;
    },
  },
};
</script>
<style lang="scss" scoped>
  .bg{
    background: #e4e4e4;
    width: 50px;
    height: 30px;
    text-align: center;
    border-radius: 10px;
    color: #666;
  }
  .span{
    color: #ff6600;
  }

  .el-col-offset-8,.el-col-offset-2 {
  .el-button {
    margin-top: 15px;
    width: 100%;
    height: 40px;
  }
}
/deep/.el-form-item__label{
  width: 50px !important;
}
/deep/.el-form-item__content{
  margin-left: 50px !important;
}
  .grey{
    color: #aaaaaa;
  }
  .product{
    display: flex;
  }
  .price{
    border-bottom: 1px solid #797979;
    padding-bottom: 10px;
    .el-col{
      display: flex;
    }
  }
  .el-row,span{
    line-height: 40px;
  }
  li{
    display: flex;
    margin-top: 5px;
  }
  .detailed{
    margin: 15px 0;
  }
  div>span{
    margin-right: 25px;
  }
  .el-row{
    margin-top: 10px;
  }
</style>
